package com.example.springhelloworld.controller;

import com.example.springhelloworld.model.DTO.StudentDTO;
import com.example.springhelloworld.model.VO.StudentVO;
import com.example.springhelloworld.pojo.Student;
import com.example.springhelloworld.services.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/uuser")
public class StudentController {
    //    @Autowired
    @Resource
    private StudentService studentService;

    //    根据id查询学生
    @GetMapping("/GetById")
    public StudentVO queryById(Integer id) {
        return studentService.queryById(id);
    }

    //根据name查询学生
    @GetMapping("/GetByName")
    public Student queryByName(String name) {
        return studentService.queryByName(name);
    }

    //添加学生
    @PostMapping("/add")
    public int addUser(StudentDTO student) {
        StudentDTO name = new StudentDTO(5, 5, 4, 4, "赵四");
        int i = studentService.addUser(name);
        return i;
    }

    //修改学生信息
    @PutMapping("/update")
    public Map<String ,Object> updateStudent(int id) {
        int i = studentService.updateStudent(2);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("msg",200);

        return map;
    }

    //删除学生信息
    @DeleteMapping("/delete")
    public Map<String ,Object> deleteStudent(int id) {
        int i = studentService.deleteStudent(id);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("msg",200);
        return map;
    }
}
